const minWeight = 40;
const maxWeight = 120;

export const getWeightList = ({ hasEmpty = true } = {}) => {
  const weightList = [];
  if (hasEmpty) {
    weightList.push('不限');
  }
  console.log(hasEmpty, 4444444)
  for (let i=minWeight; i <= maxWeight; i++)  {
    weightList.push(i);
  }
  return weightList
}

export const getWeightRange = ({ hasEmpty = true, multiple = false } = {}) => {
  if (multiple) {
    return [getWeightList({ hasEmpty }), '至', getWeightList({ hasEmpty })]
  }
  return getWeightList({ hasEmpty });
}

export const getWeightIndexs = ({ hasEmpty = true, multiple=true, value } = {}) => {
  if (!value) {
    return multiple ? [0, 0, 0] : 0
  }

  if (Array.isArray(value) && value.length == 0) {
    return multiple ? [0, 0, 0] : 0
  }
  const ageList = getWeightList({ hasEmpty });
  if (Array.isArray(value)) {
    const [minValue, maxValue] = value || [];
    const minIndex = ageList.findIndex(item => item == minValue);
    const maxIndex = ageList.findIndex(item => item == maxValue);
    return [minIndex, 0, maxIndex];
  } else {
    const index = ageList.findIndex(item => item == value);
    return index
  }
}

export const getHeightValueByIndex = ({ hasEmpty = true, index, multiple=true } = {}) => {
  const ageList = getWeightList({ hasEmpty });
  if (multiple) {
    let minValue = parseInt(ageList[index[0]]);
    let maxValue = parseInt(ageList[index[2]]);
    let result;
    if (isNaN(minValue) && isNaN(maxValue)) {
      result = [null, null];
    } else if (isNaN(minValue)){
      result = [null, maxValue]
    } else if (isNaN(maxValue)) {
      result = [minValue, null]
    } else {
      if (minValue < maxValue) {
        result = [minValue, maxValue]
      } else {
        result = [maxValue, minValue]
      }
    }

    return result;
  } else {
    let value = parseInt(ageList[index]);
    return isNaN(value) ? null : value
  }
}

// const indexs = getAgeIndexs({ value: [1991, 1996], })
// const ageRange = getAgeRange({ multiple: true })
// const ageValue = getAgeValueByIndex({ hasEmpty: true, index: [1, 0, 2], multiple: true });